package ${file.packageName};

import com.ezbuy.common.helper.ListMapper;
import com.ezbuy.common.request.GrpcMapper;
import ${file.grpcPackageName}.${file.name};

public class ${name}Mapper implements GrpcMapper<${file.name}.${name}, ${name}> {

    @Override
    public ${file.name}.${name} toGrpc(${name} entity) {
        return ${file.name}.${name}.newBuilder()
            <#list fields as field>
            <#if field.entityType=1&&field.listType=0>
                .${field.inputMethod}(new ${field.type}Mapper().toGrpc(entity.${field.name}))
            <#elseif field.entityType=1&&field.listType=1>
                .${field.inputMethod}(ListMapper.toGrpc(new ${field.singleType}Mapper(), entity.${field.name}))
            <#else>
                .${field.inputMethod}(entity.${field.name})
            </#if>
            </#list>
                .build();
    }

    @Override
    public ${name} fromGrpc(${file.name}.${name} grpc) {
        ${name} entity = new ${name}();
        <#list fields as field>
        <#if field.entityType=1&&field.listType=0>
        entity.${field.name}=new ${field.type}Mapper().fromGrpc(grpc.${field.outputMethod}());
        <#elseif field.entityType=1&&field.listType=1>
        entity.${field.name}=ListMapper.fromGrpc(new ${field.singleType}Mapper(),grpc.${field.outputMethod}());
        <#else>
        entity.${field.name}=grpc.${field.outputMethod}();
        </#if>
        </#list>
        return entity;
    }
}
